package cn.raven.system.controller;

import cn.raven.basic.annotation.PreAuthorize;
import cn.raven.basic.utils.AjaxResult;
import cn.raven.basic.utils.PageList;
import cn.raven.system.domain.SystemDicDetail;
import cn.raven.system.query.SystemDicDetailQuery;
import cn.raven.system.service.ISystemDicDetailService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**

* @Description: 数据字典类型控制层
* @Author: king
* @Version: 1.0
* @Date:  2022/6/29 9:09  
  */
@RestController
@RequestMapping("/dicdetail")
@Api(value = "数据字典的API",description="数据字典类型相关的CRUD功能")
public class SystemDicDetailController {
    @Autowired
    private ISystemDicDetailService systemDicDetailService;

    /**
    * @Title: findAll
    * @Description: 查询数据字典类型所有
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/24 9:56
    * @Parameters: []
    * @Return java.util.List<cn.raven.org.domain.systemDicDetail>
      */
    @GetMapping
    private List<SystemDicDetail> findAll(){
        return systemDicDetailService.findAll();
    }

    /**
    * @Title: findById
    * @Description: 根据id查询数据
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/24 9:57
    * @Parameters: [id]
    * @Return cn.raven.org.domain.systemDicDetail
      */
    @GetMapping("/{id}")
    @ApiOperation(value = "通过ID查询" )
    @PreAuthorize(name = "id查询数据字典",sn = "dicdetail:id")
    public SystemDicDetail findById(@ApiParam(value="根据id查询",required = true) @PathVariable("id") Long id){
        return systemDicDetailService.findOne(id);
    }

    /**
    * @Title: del
    * @Description: 根据id删除数据
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/24 9:59
    * @Parameters: [id]
    * @Return cn.raven.basic.utils.AjaxResult
      */
    @DeleteMapping("/{id}")
    @PreAuthorize(name = "删除数据字典",sn = "dicdetail:delete")
    public AjaxResult del(@PathVariable("id") Long id){
        systemDicDetailService.del(id);
        return AjaxResult.me();
    }
    
    /** 
    * @Title: save
    * @Description: 新增/修改
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/24 10:01  
    * @Parameters: [systemDicDetail]
    * @Return cn.raven.basic.utils.AjaxResult
      */
    @PutMapping
    @PreAuthorize(name = "保存数据字典",sn = "dicdetail:save")
    public AjaxResult save(@RequestBody SystemDicDetail systemDicDetail){
        try {
            if (systemDicDetail.getId() == null){
                systemDicDetailService.add(systemDicDetail);
            }else {
                systemDicDetailService.update(systemDicDetail);
            }
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请骚后重试").setSuccess(false);
        }
    }
    
    /** 
    * @Title: queryDate
    * @Description: 分页+高级查询
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/24 10:34  
    * @Parameters: [systemDicDetailQuery]
    * @Return cn.raven.basic.utils.PageList<cn.raven.org.domain.systemDicDetail>
      */
    @PostMapping
    @PreAuthorize(name = "数据字典列表",sn = "dicdetail:list")
    public PageList<SystemDicDetail> queryDate(@RequestBody SystemDicDetailQuery systemDicDetailQuery){
        return systemDicDetailService.queryData(systemDicDetailQuery);
    }
    
    /** 
    * @Title: batchDel
    * @Description: 根据ids 批量删除
    * @Author: king
    * @Version: 1.0
    * @Date:  2022/6/25 12:29
    * @Parameters: [ids]
    * @Return cn.raven.basic.utils.AjaxResult
      */
    @PatchMapping
    @PreAuthorize(name = "批量删除数据字典",sn = "dicdetail:batchDelete")
    public AjaxResult batchDel(@RequestBody Long[] ids){
        try {
            systemDicDetailService.batchDel(ids);
            return AjaxResult.me();
        } catch (Exception e) {
            e.printStackTrace();
            return AjaxResult.me().setMessage("系统繁忙,请骚后重试").setSuccess(false);
        }
    }
}
